import request from "@/utils/request";
<% if (locals.api) { %>
// #region <%= api.title %>
<%= type %>

<% if (api.req_query.length > 0 || api.req_params.length > 0 || api.query_path.params.length > 0) { _%>
export interface I<%= funcName.slice(0, 1).toUpperCase() + funcName.slice(1) %>Params {
	<% api.req_query.filter(query => query.name !== pagination.page && query.name !== pagination.size).map(query => { _%>
		<%= query.name %>?: string;
	<% }) _%>
	<% api.req_params.filter(s => s.name !== pagination.page && s.name !== pagination.size).map(query => { _%>
		<%= query.name %>?: string;
	<% }) _%>
	<% api.query_path.params.filter(s => s.name !== pagination.page && s.name !== pagination.size).map(query => { _%>
		<%= query.name %>?: string;
	<% }) _%>
	<% if (pagination.show) { _%>
		<%= pagination.page %>: number;
		<%= pagination.size %>: number;
	<% } _%>
}
<% } %> 
<% if (requestBodyType && api.req_body_other.indexOf('{}') < 0) { %>
    <%= requestBodyType %> 
<% } %> 

/**
* <%= api.title %> 
* /project/<%= api.project_id %>/interface/api/<%= api._id %> 
* @author <%= api.username %>  
* 
<% if (api.req_query.length > 0 || api.req_params.length > 0 || api.query_path.params.length > 0) { -%>* @param {I<%= funcName.slice(0, 1).toUpperCase() + funcName.slice(1) %>Params} params<%- "\n" %><% } _%>
<% if (requestBodyType && api.req_body_other.indexOf('{}')<0) { -%>* @param {I<%= funcName.slice(0, 1).toUpperCase() + funcName.slice(1) %>Data} data<%- "\n" %><% } _%>
* @returns
*/
export function <%= funcName %> (
<% if (api.req_query.length>0 || api.req_params.length > 0 || api.query_path.params.length > 0) { %>
params: I<%= funcName.slice(0, 1).toUpperCase() + funcName.slice(1) %>Params,
<% } _%>
<% if (requestBodyType) { %> 
data: I<%= funcName.slice(0, 1).toUpperCase() + funcName.slice(1) %>Data
<% } %> 
) {
return request<<%= typeName %>["result"]>({
	  url: `http://127.0.0.1:3001<%= api.query_path.path.replace(/\{/g,"${params.") %>`, 
		method: '<%= api.method %>',
		<% if(api.req_query.length>0 || api.req_params.length > 0) { %>params,<% } _%>
        <% if (requestBodyType && api.req_body_other.indexOf('{}')<0) {%>data,<% } %> 
	})
}
// #endregion
<% } else { %>
// #region
export interface I<%= fetchName.slice(0, 1).toUpperCase() + fetchName.slice(1) %>Result {
  code: number;
	msg: string;
	<% if (!pagination.show) { _%>
	result: {
		<% columns.map((item, index) => { _%>
			<%= item.key || `column${index+1}` %>: string;
		<% }) _%>
		}[];
	<% } else { _%>
		result: {
			records: {
				<% columns.map((item, index) => { _%>
					<%= item.key || `column${index+1}` %>: string;
				<% }) _%>
			}[];
			total: number;
		}
	<% } _%>
}

export interface I<%= fetchName.slice(0, 1).toUpperCase() + fetchName.slice(1) %>Params {
	<% filters.map(item => { _%>
		<%= item.key %>?: string;
	<% }) _%>
	<% if (pagination.show) { _%>
		<%= pagination.page %>: number;
		<%= pagination.size %>: number;
	<% } _%>
}

export function <%= fetchName %>(
params: I<%= fetchName.slice(0, 1).toUpperCase() + fetchName.slice(1) %>Params
) {
return request<I<%= fetchName.slice(0, 1).toUpperCase() + fetchName.slice(1) %>Result["result"]>({
	url: `http://127.0.0.1:3001/<%= createBlockPath %>/<%= fetchName %>`, 
	method: 'GET',
	params,
});
}
// #endregion
<% } %>